﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Dapper;
using System.Data;
using DapperExtensions;
using System.Data.SqlClient;

namespace LPF.Lib.DataAccess
{
    public class TestDapper
    {
        string _conString = "Data Source=HUYTUAN-PC;Initial Catalog=LPF;Integrated Security=True";

        public Product Insert()
        {
            using (var con = new SqlConnection(_conString))
            {
                var entity = new Product
                {
                    ProductName = "Product 1",
                    UnitOfWeight = 0,
                    UnitPrice = 70000
                };

                con.Open();
                var m = con.Insert(entity);
                con.Close();
                return new Product
                {
                    UnitPrice = m.UnitPrice,
                    Notes = m.Notes,
                    ProductName = m.ProductName,
                    ProductSign = m.ProductSign,
                    SellingPrice = m.SellingPrice,
                    UnitOfWeight = m.UnitOfWeight
                };
            }
        }

        public Product Delete()
        {
            using (var con = new SqlConnection(_conString))
            {
                
                con.Open();
                var g = con.Get<Product>(new {ProductName = "Product 1"});
                var d = con.Delete(g);
                con.Close();
                return d ? g : null;
            }
        }
    }
}
